//引入express模块
const {Router, request, response}=require('express');
//引入SQLModules
const connection=require('../SQLModules/dbConnection');//获取数据库连接
const {CompreScoreQuery}=require('../SQLModules/CityInfoQuerySQL');//获取SQL查询语句
const { connect, query } = require('../SQLModules/dbConnection');

//创建路由对象
const route=new Router();

//数据库查询
route.get('/demo/data',(request,response)=>{
  connection.query(CompreScoreQuery.queryScoreByCityName,'三门峡市',(err,res,field)=>{
    console.log(res);
    response.send(res);
  })
})

//综合得分信息查询
route.get("/index/getTotalScore.json",(request,response)=>{
  //获取查询字段
  let queryInfo=request.query.value;
  //数据库查询
  connection.query(CompreScoreQuery.queryScoreByCityName,queryInfo,(err,res,field)=>{
    //异常处理
    try{
      if(err) throw err;
      console.log(res);
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  })
})

//按照年份获取人均GDP
route.get('/index/allCityPerGDP.json',(request,response)=>{
   //获取查询字段
   let queryInfo=request.query.sqlQuery;
   //数据库查询
   connection.query(queryInfo,(err,res,field)=>{
    //异常处理
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  })
});


//获取城市群的信息
route.get("/index/CityTotalScoreInfo.json",(request,response)=>{
  let sqlQuery=request.query.sqlQuery;
  // console.log(sqlQuery)
  connection.query(sqlQuery,(err,res,field)=>{
    //异常处理
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  })
})

//获取常住人口的信息
route.get("/index/population.json",(request,response)=>{
  //获取查询字段
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  })
})

//获取总GDP的值
route.get("/index/totalGDP.json",(request,response)=>{
  //获取查询字段
  let queryInfo=request.query.sqlQuery;
  //查询数据库
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
});

//获取总的财政收入
route.get("/index/financeIncomeAndOutCome.json",(request,response)=>{
    //获取查询字段
    let queryInfo=request.query.sqlQuery;
    //查询数据库
    connection.query(queryInfo,(err,res,field)=>{
      try{
        if(err) throw err;
        response.send(res);
      }catch(err){
        response.send('unKnown');
      }
    });
});

//获取人均教育事业费支出
route.get("/index/perEduOutCome.json",(request,response)=>{
  //获取查询字段
  let queryInfo=request.query.sqlQuery;
  //查询数据库
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//获取人均科学事业费用支出
route.get("/index/PerScienceOutCome.json",(request,response)=>{
   //获取查询字段
   let queryInfo=request.query.sqlQuery;
   //查询数据库
   connection.query(queryInfo,(err,res,field)=>{
     try{
       if(err) throw err;
       response.send(res);
     }catch(err){
       response.send('unKnown');
     }
   });
})

//获取年末城乡居民储蓄余额PerSaveMoneyByYear
route.get("/index/perSaveMoney.json",(request,response)=>{
  //获取查询字段
  let queryInfo=request.query.sqlQuery;
  //查询数据库
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  })
})

//查询第二产业比重
route.get("/index/SecondaryRate.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//查询第三产业比重
route.get("/index/thirdRate.json",(request,response)=>{
     //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//获取外商投资占总GDP的比例
route.get("/index/ForeignRate.json",(request,response)=>{
      //获取查询信息
      let queryInfo=request.query.sqlQuery;
      //数据库查询
      connection.query(queryInfo,(err,res,field)=>{
        try{
          if(err) throw err;
          response.send(res);
        }catch(err){
          response.send('unKnown');
        }
      });
})

//获取人均医疗资源数量
route.get("/index/MedicalSource.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//每万人中的互联网人数
route.get("/index/InternetAmout.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//获取因子分析结果-城市综合得分
route.get("/index/comScore.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
});

//获取城市的地理坐标
route.get("/index/CityGeoLocations.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
});

//获取城市得分
route.get("/index/cityBasicInfo.json",(request,response)=>{
  //获取查询信息
  let queryInfo=request.query.sqlQuery;
  // console.log(queryInfo)
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//获取产业占比
route.get("/index/IndustryPercent.json",(request,response)=>{
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})

//获取基尼系数的信息
route.get("/welcome/GiNiInfo.json",(request,response)=>{
  let queryInfo=request.query.sqlQuery;
  //数据库查询
  connection.query(queryInfo,(err,res,field)=>{
    try{
      if(err) throw err;
      response.send(res);
    }catch(err){
      response.send('unKnown');
    }
  });
})


//导出当前模块
module.exports=function(){
  return route;
}